package simel;

public class Elevator
{
    private int floorMin, floorMax;

    /** where is the elevator now? **/
    private int floor;

    /** Where is the elevator headed? **/
    private int floorDestination;

    public Elevator(int floorMin, int floorMax)
    {
        this.floorMin = floorMin;
        this.floorMax = floorMax;
        this.floorDestination = floorMin;
        this.floor = floorMin;
    }

    /** Where is the elevator now? **/
    public int getFloor()
    {
        return floor;
    }

    /** What is the lowest floor this elevator can visit? **/
    public int getFloorMin()
    {
        return floorMin;
    }

    /** What is the highest floor this elevator can visit? **/
    public int getFloorMax()
    {
        return floorMax;
    }

    /** Tell the elevator to go to this location **/
    public void setDestination(int dest)
    {
        floorDestination = dest;
    }

    /** Where was the last destination set to? **/
    public int getDestination()
    {
        return floorDestination;
    }

    /** returns 1 if the elevator is headed up, -1 if down, 0 if stationary. **/
    public double getDirection()
    {
        if (floorDestination < floor)
            return -1;
        if (floorDestination > floor)
            return 1;
        return 0;
    }

    /** Only to be called by simulator **/
    protected void update()
    {
        int d = getDestination();
        if (d > getFloor() + 1)
            d = getFloor() + 1;
        if (d < getFloor() - 1)
            d = getFloor() - 1;
        d = Math.min(getFloorMax(), d);
        d = Math.max(getFloorMin(), d);

        floor = d;
    }
}
